<template>
  <div>
    <el-table
      border
      stripe
      :data="results.filter((val) => {
        return +val.dist === 9
      })"
      :height="height"
      @row-dblclick="detail"
    >
      <el-table-column
        label="编号"
        width="80"
        align="center"
        :formatter="formatter"
        type="index"
      />
      <el-table-column
        label="所在地块"
        prop="field"
        align="center"
      >
        <template #default="scope">
          {{ getAttr(scope.row.plant.field_id,'id',fields) }}
        </template>
      </el-table-column>
      <el-table-column
        label="作物"
        prop="crop"
        align="center"
      >
        <template #default="scope">
          {{ getAttr(scope.row.plant.crop_id,'id',crops) }}
        </template>
      </el-table-column>
      <el-table-column
        label="预计灌水日"
        prop="created_at"
        align="center"
        :formatter="formatter"
      />
      <el-table-column
        label="预计灌水量(mm)"
        prop="amount"
        align="center"
        :formatter="formatter"
        width="160"
      />
      <!-- <el-table-column
        label="实施状态"
        prop="status"
        align="center"
      >
        <template v-slot="scope">
          <el-tag v-if="!scope.row.do_at" type="danger">未实施</el-tag>
          <el-tag v-else type="success">已实施</el-tag>
        </template>
      </el-table-column> -->
      <el-table-column
        label="操作"
        prop="status"
        align="center"
        width="120"
      >
        <template v-slot="scope">
          <el-link type="primary" icon="el-icon-document" @click="detail(scope.row)">查看详情</el-link>
        </template>
      </el-table-column>
    </el-table>
  </div>

</template>

<script>
import { mapGetters } from 'vuex'
import { getAttr, formatterForTable } from '@/utils'
export default {
  props: {
    results: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      height: 'calc(100vh - 224px)'
    }
  },
  computed: {
    ...mapGetters(['crops', 'fields'])
  },
  methods: {
    detail(row) {
      this.$emit('detail', row)
    },
    formatter(row, column) {
      return formatterForTable(row, column)
    },
    getAttr(value, name, datas) {
      return getAttr(value, name, datas)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>

